package edu.qc.cs370.project1;

import java.util.ArrayList;
import java.util.Random;

public class Player {
	private String name = "";
	private int score = 0;
	private int money;
	private int playerType = 0;
	private ArrayList<Card> hand = new ArrayList<Card>();
	private boolean stillIn = true;
	private boolean winner = false;
	private Random rand = new Random();
	private boolean hit = true;
	
	//HUMAN = 0;
	//COMPUTER = 1;
	//DEALER = 2;

	public int getPlayerType() {
		return playerType;
	}

	public void setPlayerType(int playerType) {
		this.playerType = playerType;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public int getMoney() {
		return money;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public ArrayList<Card> showHand() {
		return hand;
	}

	public void setHand(ArrayList<Card> hand) {
		this.hand = hand;
	}

	public void insertCard(Card c) {
		hand.add(c);
		int aceCount = 0;
		score = 0;

		//count aces and score all OTHER cards
		for(int i = 0; i<hand.size(); i++){
			if(hand.get(i).getSuit() == 'A')
				aceCount++;
			else
				score += hand.get(i).getValue();
		}
		
		while (aceCount>1){
			score ++;
			aceCount--;
		}
		
		if (aceCount > 0 && (score+11)<=21)
			score += 11;
		else if (aceCount > 0 && (score+11)>21)
			score ++;
	}

	public boolean toStay() {
		if (hand == null) {
			return false;
		}

		if (playerType == 2) {
			if (score >= 17) {
				return true;
			} else {
				return false;
			}
		} else if (playerType == 1) {
			if (score > 14) {
				Random random = new Random();
				return random.nextBoolean();
			} else {
				return false;
			}
		}

		return false;
	}

	
	public void setStillIn(boolean stillIn) {
		this.stillIn = stillIn;
	}

	public boolean isStillIn() {
		return stillIn;
	}

	public void removePlayer()
	{
		
	}
	
	public void setWinnerStatus(boolean s)
	{
		this.winner = s;
	}
	
	public boolean getWinnerStatus()
	{
		return this.winner;
	}
}
